package trading.ctm.yunjing.module.auction.activity

import android.content.Intent
import android.opengl.Visibility
import android.os.Bundle
import android.view.View
import android.widget.EditText
import android.widget.ImageView
import android.widget.TextView
import cc.vv.baselibrary.activity.BaseActivity
import cc.vv.baselibrary.util.LKDialogUtil
import cc.vv.baselibrary.view.BaseTopBarView
import kotlinx.android.synthetic.main.activity_auction_detail.*
import kotlinx.android.synthetic.main.layout_medical_detail.*
import kotlinx.android.synthetic.main.layout_price_broken.*
import kotlinx.android.synthetic.main.layout_quality_report.*
import trading.ctm.yunjing.R
import trading.ctm.yunjing.module.mine.activity.PayCashDepositActivity

/**
 * @desc 拍卖详情
 * @author zouxiaorui
 * @date  2018/8/8
 */
class AuctionDetailsActivity : BaseActivity() {

    private val yList = ArrayList<Double>()
    private val xRawDatas = ArrayList<String>()

    override fun initLayoutRes(): Int {
        return R.layout.activity_auction_detail
    }

    override fun initView(bundle: Bundle?) {
        super.initView(bundle)
        btbv_auction_detail_title.setWhetherShowDividerView(false)
        setIvVisible(0)
    }

    override fun initAction(data: Bundle?) {
        super.initAction(data)

        //标题栏
        btbv_auction_detail_title.setEventInterface(object : BaseTopBarView.EventInterface {
            override fun leftOnClick() {
                finish()
            }

            override fun leftCloseClick() {
            }

            override fun rightOnClick() {
            }

        })
        btbv_auction_detail_title.rightTV.setOnClickListener {
            startActivity(Intent(this@AuctionDetailsActivity, AuctionRegulationActivity::class.java))
        }

        var data = arrayListOf("http://img15.3lian.com/2015/f1/90/d/106.jpg",
                "http://pic34.nipic.com/20131016/7487939_145711674162_2.jpg",
                "http://attach.bbs.miui.com/forum/201312/18/204803vxvoqod4hohod8dn.jpg",
                "http://pic29.nipic.com/20130520/7487939_205025481178_2.jpg")

        //广告轮播
        ibv_ad_auction_icon.initWHPercentage(210, 375, -1)
        ibv_ad_auction_icon.initImgData(data) { imgPath, position ->
        }
        ibv_ad_auction_icon.initIndicatorView(R.mipmap.icon_ctm_no_selector, R.mipmap.icon_ctm_selector, 8, 8)

        //药材名
        tv_ad_medicinal_name
        //品规
        tv_ad_product_gauge
        //拍卖数量
        tv_ad_auction_number
        //产地
        tv_ad_producing_area
        //起拍价
        tv_auction_starting_price
        //竞价阶梯
        tv_auction_bidding_ladder
        //竞拍次数
        tv_auction_numbers
        //最新报价
        tv_ad_new_price
        //拍卖时间
        tv_ad_auction_time


        //竞拍次数
        tv_auction_numbers.setOnClickListener {
            startActivity(Intent(this@AuctionDetailsActivity, AuctionListActivity::class.java))
        }

        //药材详情
        tv_ad_medicinal_detail.setOnClickListener {
            setIvVisible(0)
        }
        //质检报告
        tv_ad_check_report.setOnClickListener {
            setIvVisible(1)
        }
        //价格走势
        tv_ad_price_trend.setOnClickListener {
            setIvVisible(2)
        }

        //竞拍榜单
        tv_auction_numbers.setOnClickListener {
            startActivity(Intent(this@AuctionDetailsActivity, AuctionListActivity::class.java))
        }

        //缴纳保证金
        tv_ad_pay_rule.setOnClickListener {
            startActivity(Intent(this@AuctionDetailsActivity, PayCashDepositActivity::class.java))
        }

        //报价
        tv_ad_offer.setOnClickListener {
            initOfferDialog()
        }
        yList.clear()
        xRawDatas.clear()
        yList.add(86.8)
        yList.add(75.2)
        yList.add(98.0)
        yList.add(82.1)
        yList.add(111.5)
        yList.add(70.5)
        yList.add(62.5)
        yList.add(86.8)
        yList.add(75.2)
        yList.add(98.0)
        yList.add(82.1)
        yList.add(111.5)
        yList.add(70.5)
        yList.add(62.5)
        xRawDatas.add("2018/01")
        xRawDatas.add("2018/02")
        xRawDatas.add("2018/03")
        xRawDatas.add("2018/04")
        xRawDatas.add("2018/05")
        xRawDatas.add("2018/06")
        xRawDatas.add("2018/07")
        xRawDatas.add("2018/01")
        xRawDatas.add("2018/02")
        xRawDatas.add("2018/03")
        xRawDatas.add("2018/04")
        xRawDatas.add("2018/05")
        xRawDatas.add("2018/06")
        xRawDatas.add("2018/07")
        var a = 150
        var b = a / 5
        lgv_ad_yLine.setData(yList, a, b)
        lgv_ad_brokenLine.setData(yList, xRawDatas, a, b, ll_ad_top)
    }

    private fun setIvVisible(i: Int): Unit {
        when (i) {
            0 -> {

                tv_ad_medicinal_detail.isSelected = true
                tv_ad_check_report.isSelected = false
                tv_ad_price_trend.isSelected = false

                ll_adMed_medDetail.visibility = View.VISIBLE
                ll_adMed_priceBroken.visibility = View.GONE
                ll_adMed_qualityReport.visibility = View.GONE

                iv_ad_medicinal_icon.visibility = View.VISIBLE
                iv_ad_check_icon.visibility = View.GONE
                iv_ad_price_icon.visibility = View.GONE

            }
            1 -> {
                tv_ad_medicinal_detail.isSelected = false
                tv_ad_check_report.isSelected = true
                tv_ad_price_trend.isSelected = false

                ll_adMed_medDetail.visibility = View.GONE
                ll_adMed_priceBroken.visibility = View.GONE
                ll_adMed_qualityReport.visibility = View.VISIBLE

                iv_ad_medicinal_icon.visibility = View.GONE
                iv_ad_check_icon.visibility = View.VISIBLE
                iv_ad_price_icon.visibility = View.GONE
            }
            2 -> {
                tv_ad_medicinal_detail.isSelected = false
                tv_ad_check_report.isSelected = false
                tv_ad_price_trend.isSelected = true

                ll_adMed_medDetail.visibility = View.GONE
                ll_adMed_priceBroken.visibility = View.VISIBLE
                ll_adMed_qualityReport.visibility = View.GONE

                iv_ad_medicinal_icon.visibility = View.GONE
                iv_ad_check_icon.visibility = View.GONE
                iv_ad_price_icon.visibility = View.VISIBLE
            }
        }
    }

    private fun initOfferDialog(): Unit {
        val view = View.inflate(this@AuctionDetailsActivity, R.layout.dialog_auction_offer, null)
        val iv_offer_close = view.findViewById<ImageView>(R.id.iv_offer_close)
        val tv_auction_offer_remind = view.findViewById<TextView>(R.id.tv_auction_offer_remind)
        val tv_auction_offer_price = view.findViewById<TextView>(R.id.tv_auction_offer_price)
        val tv_auction_offer_affirm = view.findViewById<TextView>(R.id.tv_auction_offer_affirm)
        val et_auction_offer_amount = view.findViewById<EditText>(R.id.et_auction_offer_amount)
        val et_auction_offer_min_price = view.findViewById<EditText>(R.id.et_auction_offer_min_price)
        val et_auction_offer_max_price = view.findViewById<EditText>(R.id.et_auction_offer_max_price)

        val dialog = LKDialogUtil.getBottomDialog(this@AuctionDetailsActivity, view)

        iv_offer_close.setOnClickListener {
            dialog.dismiss()
        }

        tv_auction_offer_affirm.setOnClickListener {
            var offerAmount = et_auction_offer_amount.text.toString()
            var minPrice = et_auction_offer_min_price.text.toString()
            var maxPrice = et_auction_offer_max_price.text.toString()
            dialog.dismiss()
        }
        dialog.show()
    }

}